//
//  KaChing_AppAppDelegate.m
//  KaChing_App
//
//  Created by Jordan Robert Yust on 2/4/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "KaChing_AppAppDelegate.h"
#import "Constants.h"
#import "Home_VC.h"
#import "Holdings_TableVC.h"
#import "Watchlist_TableVC.h"
#import "Trade_VC.h"


@implementation KaChing_AppAppDelegate

@synthesize window;
@synthesize settingsNavController;
@synthesize mainTabBarController;
@synthesize dataManager;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

	[window addSubview:settingsNavController.view];
	[window makeKeyAndVisible];
}

- (void) enterProfile
{
	/* Debugging */
	NSLog(@"TEST METHOD ENTERED!!!!");
	NSLog(@"\n\nInside AppDelegate!!\nRemotekey: %@\nUserID: %d", [dataManager remoteKey], [dataManager userID]);

	/* The settings navController is no longer needed, therefore release it */
	[settingsNavController release];
	
	/*
	 Here is what's taking place:
	 Prior to entering this method, the DataManager object was created for the selected UserID/RemoteKey pair in the UserAttr_TableVC class.  That object
	 was then passed onto this class (the AppDelegate). Therefore, when entering this method, this class' DataManager object has already been created. Now it  needs
	 to be filtered into all the classes that need to access the DataManager object (e.g., Holdings_TableVC, Watchlist_TableVC, etc.) Each of the following lines of code
	 passes the DataManager object into a class that needs it.  The lines are as follows:
	 1. DataManager passed into the Home_VC
	 2. DataManager passed into the Holdings_TableVC
	 3. DataManager passed into the Watchlist_TableVC
	 4. DataManager passed into the Trade_VC
	 */
/* 1. */	[(          Home_VC *)[(UINavigationController *)[[self.mainTabBarController viewControllers] objectAtIndex:homeNavControllerIndex		] topViewController] setDataManager:dataManager];
/* 2. */	[( Holdings_TableVC *)[(UINavigationController *)[[self.mainTabBarController viewControllers] objectAtIndex:holdingsNavControllerIndex	] topViewController] setDataManager:dataManager];
/* 3. */	[(Watchlist_TableVC *)[(UINavigationController *)[[self.mainTabBarController viewControllers] objectAtIndex:watchlistNavControllerIndex	] topViewController] setDataManager:dataManager];
/* 4. */	[(         Trade_VC *)[(UINavigationController *)[[self.mainTabBarController viewControllers] objectAtIndex:tradeNavControllerIndex		] topViewController] setDataManager:dataManager];

	
	/* Transition to the NavController that controls the Home_VC */
	[self.mainTabBarController setSelectedIndex:homeNavControllerIndex];

	[window addSubview:mainTabBarController.view];
	
	NSLog(@"TEST METHOD EXITED!!!");	// debugging
	
}

/*
 ------------------------------------------------------------------------
 UITabBarControllerDelegate Protocol methods
 ------------------------------------------------------------------------
 */

#pragma mark --
#pragma mark UITabBarControllerDelegate Protocol methods

/*
// Optional UITabBarControllerDelegate method
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
*/

/*
// Optional UITabBarControllerDelegate method
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
}
*/

#pragma mark --

- (void)dealloc
{
	[dataManager release];
//  [settingsNavController release];  // Check this class' methods, this object was released in one of those.  Need to verify though.
	[mainTabBarController release];
    [window release];
    [super dealloc];
}

@end

